package com.projects.android.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.projects.android.R;
import com.projects.android.dto.OrdersDTO;

public class ManageOrdersAdapter extends ArrayAdapter<OrdersDTO> {
	private LayoutInflater mInflater;

	public ManageOrdersAdapter(Context context, int resource, int textViewResourceId,
			List<OrdersDTO> objects) {
		super(context, resource, textViewResourceId, objects);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ManageOrdersViewHolder holder = null;
		TextView idorder = null;
		TextView orderdate = null;
		TextView restaurant = null;
		OrdersDTO rowData = getItem(position);

		if (null == convertView) {
			convertView = mInflater.inflate(R.layout.orderitem, null);
			holder = new ManageOrdersViewHolder(convertView);
			convertView.setTag(holder);
		}

		holder = (ManageOrdersViewHolder) convertView.getTag();

		idorder = holder.getIDOrder();
		idorder.setText(String.valueOf(rowData.getID()));

		orderdate = holder.getOrderDate();
		orderdate.setText(rowData.getOrderDate());
		
		restaurant = holder.getRestaurant();
		restaurant.setText(rowData.getRestaurant().getName());

		return convertView;
	}
}
